//
//  SelectUserViewController.m
//  HGMMT
//
//  Created by huan liu on 2019/1/4.
//  Copyright © 2019年 eport_user1. All rights reserved.
//

#import "SelectUserViewController.h"
#import "UserModel.h"
#import "DataSave.h"

static NSString *iden_cell = @"iden_cell";

@interface SelectUserViewController ()<UITableViewDelegate,UITableViewDataSource>

@property(nonatomic,strong)UITableView *tableView;

@end

@implementation SelectUserViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self initNav];
    [self initUI];
}

-(void)initNav{
    
    self.title = @"选择用户信息";
    
    UIBarButtonItem *item = [[UIBarButtonItem alloc]initWithTitle:@"取消" style:(UIBarButtonItemStylePlain) target:self action:(@selector(rightButtonAction:))];
    self.navigationItem.rightBarButtonItem = item;
    
}

-(void)rightButtonAction:(UIButton *)btn{
    
    [self dismissViewControllerAnimated:YES completion:nil];
    
}


-(void)initUI{
    
    self.tableView = [[UITableView alloc]initWithFrame:HG_SCREEN_BOUNDS style:(UITableViewStylePlain)];
    self.tableView.backgroundColor = [UIColor whiteColor];
    self.tableView.dataSource = self;
    self.tableView.delegate = self;
    self.tableView.tableFooterView = [UIView new];
    [self.view addSubview:self.tableView];
    
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{

    return  self.userInfoArray.count;
    
    
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:iden_cell];
    
    if (cell == nil) {
        
        cell = [[UITableViewCell alloc]initWithStyle:(UITableViewCellStyleDefault) reuseIdentifier:iden_cell];
        
    }
    UserModel *model = self.userInfoArray[indexPath.row];
    
    cell.textLabel.text = model.username;
    
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    
    return cell;
    
}

-(CGFloat )tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    
    return 55;
    
}


-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    UserModel *Model = self.userInfoArray[indexPath.row];
    
    [[DataSave shareInstance] saveUserInfo:Model];
    
    [self dismissViewControllerAnimated:YES completion:nil];
    
}

@end
